import UIKit
import SVProgressHUD
import Flutter
import Alamofire
import SwiftyJSON
import IQKeyboardManagerSwift
import Kingfisher
@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
    override func application(
        _ application: UIApplication,
        didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
    ) -> Bool {
        GeneratedPluginRegistrant.register(with: self)
        FlutterMethodPlugin.register(with: self.registrar(forPlugin: "FlutterMethodPlugin")!);
        SVProgressHUD.setDefaultStyle(.dark);
        SVProgressHUD.setMinimumDismissTimeInterval(2);
        onInit();
        return super.application(application, didFinishLaunchingWithOptions: launchOptions)
    }
    
    func onInit() -> Void {
        AFUtils.request(method: .post, URLString: "https://api.qiudasheng.com/resource/app-do/list", parameters: nil);
        IQKeyboardManager.shared.enable = false;
        initJson()
        imageview()
    }
    
    func initJson() -> Void {
        
        let viewController = VC1()
        if let file = Bundle.main.path(forResource: "user", ofType: "json") {
            do {
                let data = try Data(contentsOf: URL(fileURLWithPath: file))
                let json = try JSON(data: data)
                viewController.json = json
                print(json)
            } catch {
                viewController.json = JSON.null
                print("error");
            }
        } else {
            viewController.json = JSON.null
            
        }
    }
    
    func imageview() -> Void {
        let imageView = UIImageView(frame: CGRectMake(0, 0, 100, 100))
        let url = URL(string: "https://oss.qiudasheng.com/prod/resource/20230629/qxbaesy.jpg")
        let processor = DownsamplingImageProcessor(size: imageView.bounds.size)
                     |> RoundCornerImageProcessor(cornerRadius: 20)
        
        imageView.kf.indicatorType = .activity
        imageView.kf.setImage(
            with: url,
            placeholder: UIImage(named: "placeholderImage"),
            options: [
                .processor(processor),
                .scaleFactor(UIScreen.main.scale),
                .transition(.fade(1)),
                .cacheOriginalImage
            ])
        {
            result in
            switch result {
            case .success(let value):
                print("Task done for: \(value.source.url?.absoluteString ?? "")")
            case .failure(let error):
                print("Job failed: \(error.localizedDescription)")
            }
        }
    }
    
    
}
